import os
from pathlib import Path

# 配置常量
BEFORE_FOLDER = "before"
AFTER_FOLDER = "after"
DIFF_FOLDER = "diff"

# 支持的代码文件扩展名
CODE_EXTENSIONS = {
    '.py', '.js', '.java', '.c', '.cpp', '.h', '.hpp', '.go', '.rs', 
    '.php', '.rb', '.swift', '.kt', '.scala', '.m', '.sh', '.html', 
    '.css', '.scss', '.less', '.vue', '.ts', '.json', '.xml', '.yml', 
    '.yaml', '.md', '.txt'
}

# HTML模板配置
HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>代码差异对比 - {filename}</title>
    <style>
        body {{
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            margin: 20px;
            background-color: #f5f5f5;
        }}
        .container {{
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }}
        .header {{
            border-bottom: 2px solid #333;
            padding-bottom: 10px;
            margin-bottom: 20px;
        }}
        .file-info {{
            color: #666;
            margin-bottom: 10px;
        }}
        .diff-section {{
            margin-bottom: 30px;
            border: 1px solid #ddd;
            border-radius: 5px;
            overflow: hidden;
        }}
        .diff-header {{
            background-color: #f8f9fa;
            padding: 10px;
            font-weight: bold;
            border-bottom: 1px solid #ddd;
        }}
        .added {{
            background-color: #d4edda;
            border-left: 4px solid #28a745;
            padding: 2px 6px;
            margin: 1px 0;
        }}
        .removed {{
            background-color: #f8d7da;
            border-left: 4px solid #dc3545;
            padding: 2px 6px;
            margin: 1px 0;
            text-decoration: line-through;
            opacity: 0.7;
        }}
        .unchanged {{
            background-color: #f8f9fa;
            padding: 2px 6px;
            margin: 1px 0;
        }}
        .line-number {{
            color: #999;
            user-select: none;
            width: 40px;
            display: inline-block;
        }}
        .code-content {{
            margin-left: 10px;
        }}
        .stats {{
            background-color: #e9ecef;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
            font-size: 14px;
        }}
        .summary {{
            display: flex;
            gap: 20px;
            margin-bottom: 10px;
        }}
        .summary-item {{
            padding: 5px 10px;
            border-radius: 3px;
            color: white;
            font-weight: bold;
        }}
        .summary-added {{ background-color: #28a745; }}
        .summary-removed {{ background-color: #dc3545; }}
        .summary-modified {{ background-color: #ffc107; color: #333; }}
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>代码差异对比报告</h1>
            <div class="file-info">文件: {filename}</div>
            <div class="file-info">对比时间: {timestamp}</div>
        </div>
        
        <div class="stats">
            <div class="summary">
                <div class="summary-item summary-added">新增: {added_count} 行</div>
                <div class="summary-item summary-removed">删除: {removed_count} 行</div>
                <div class="summary-item summary-modified">修改: {modified_count} 行</div>
            </div>
            <div class="summary">
                <span><strong>总计变化:</strong> {total_changes} 行</span>
            </div>
        </div>

        {diff_content}
    </div>
</body>
</html>
"""